package io.renren;

import io.renren.modules.eightapp.service.EiParkingInfoService;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.swing.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class test {
    @Autowired
    private EiParkingInfoService eiParkingInfoService;

    @Test
    public List<List> readfile(){
        List<List> datas = new ArrayList<>();
        List data=null;
        String  Path=System.getProperty("user.dir");
        String  filePath=Path.substring(0,Path.lastIndexOf("\\"))+System.getProperty("file.separator")+"files"+System.getProperty("file.separator")+"park"+System.getProperty("file.separator")+"1"+".xlsx";
        try {
            File fis = new File(filePath);
            Workbook workbook = WorkbookFactory.create(fis);
            // 获得工作表个数
            int sheetCount = workbook.getNumberOfSheets();
            // 遍历工作表
            for(int i = 0;i<sheetCount;i++) {
                //读取第i个工作表
                Sheet sheet = workbook.getSheetAt(i);
                //获取最后一行的num，即总行数。此处从0开始
                int maxRow = sheet.getLastRowNum();

                for (int row = 0; row <= maxRow; row++) {
                    //获取最后单元格num，即总单元格数 ***注意：此处从1开始计数***
                    int maxRol = sheet.getRow(row).getLastCellNum();
                    data=new ArrayList();
                    if(maxRow==0){
                        continue;
                    }
                    for (int rol = 0; rol < maxRol; rol++){
                        data.add(sheet.getRow(row).getCell(rol));
                        System.out.println("SUC");
                    }
                    datas.add(data);
                }
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return datas;
    }

    @Test
    public void test(){


    }
}
